//package editor.cn;
////Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one
//// sorted array.
////
//// Note:
////
////
//// The number of elements initialized in nums1 and nums2 are m and n respectivel
////y.
//// You may assume that nums1 has enough space (size that is equal to m + n) to h
////old additional elements from nums2.
////
////
//// Example:
////
////
////Input:
////nums1 = [1,2,3,0,0,0], m = 3
////nums2 = [2,5,6],       n = 3
////
////Output: [1,2,2,3,5,6]
////
////
////
//// Constraints:
////
////
//// -10^9 <= nums1[i], nums2[i] <= 10^9
//// nums1.length == m + n
//// nums2.length == n
////
//// Related Topics 数组 双指针
//// 👍 640 👎 0
//
//
//import java.util.Arrays;
//
////leetcode submit region begin(Prohibit modification and deletion)
//class Solution {
//    public void merge(int[] nums1, int m, int[] nums2, int n) {
////        System.arraycopy(nums2, 0, nums1, m, n);
////        Arrays.sort(nums1);
//
//        // Make a copy of nums1.
//        int [] nums1_copy = new int[m];
//        System.arraycopy(nums1, 0, nums1_copy, 0, m);
//
//        // Two get pointers for nums1_copy and nums2.
//        int p1 = 0;
//        int p2 = 0;
//
//        // Set pointer for nums1
//        int p = 0;
//
//        // Compare elements from nums1_copy and nums2
//        // and add the smallest one into nums1.
//        while ((p1 < m) && (p2 < n))
//            nums1[p++] = (nums1_copy[p1] < nums2[p2]) ? nums1_copy[p1++] : nums2[p2++];
//
//        // if there are still elements to add
//        if (p1 < m)
//            System.arraycopy(nums1_copy, p1, nums1, p1 + p2, m + n - p1 - p2);
//        if (p2 < n)
//            System.arraycopy(nums2, p2, nums1, p1 + p2, m + n - p1 - p2);
//
//    }
//}
////leetcode submit region end(Prohibit modification and deletion)
